const {ImgList, sequelize} = require('./models/imglist');

let _ = require('lodash');
const fs = require('fs').promises;


// {"MRF": "ISS072-E-400923", "FCLT": 200.0, "ELEV": 59.0, "timestamp": "2024-12-21", "CLDP": null, "FEAT": "", "spatial_resolution": 11.26, "epoch_time": 1734779916.0}



let thumbnaillist = [
  'd:/xiangmu/shujuguanli/suoluetu/taiwan13-0.png',
  'd:/xiangmu/shujuguanli/suoluetu/taiwan13-1.png',
  'd:/xiangmu/shujuguanli/suoluetu/taiwan13-2.png',
]
let imgpathlist = [
  'd:/xiangmu/shujuguanli/yingxiang/taiwan13-0.tif',
  'd:/xiangmu/shujuguanli/yingxiang/taiwan13-1.tif',
  'd:/xiangmu/shujuguanli/yingxiang/taiwan13-2.tif',
]

let desclist = [
  '台北',
  '台中',
  '台南',
]

let namelist = [
  'taiwan13-0.tif',
  'taiwan13-1.tif',
  'taiwan13-2.tif',
]

let itemone = {
  name: '',
  linerange: '',
  location: '',
  thumbnail: '',
  desc: '台湾',
  imgpath: '',
  imgtime: new Date(),
  remark: '',
  resolution: '',
}


let itemlist = []


async function main(params) {
  
  // 读取json并构造数据
  const data = await fs.readFile('d.json', 'utf8');
  const jsonData = JSON.parse(data);
  jsonData.features.map(item => {
  
    let iindex = _.random(0, 2)
  
    item.geometry.coordinates
  
    itemone.desc = item.properties.desc
    itemone.thumbnail = item.properties.thumbnail
    itemone.imgpath = item.properties.imgpath
    itemone.name = item.properties.name


    itemone.imgtime = new Date(item.properties.timestamp)
    itemone.remark = item.properties.MRF
    itemone.resolution = item.properties.spatial_resolution * 1.0
  
    itemone.linerange = {
      type: 'Polygon',
      coordinates: item.geometry.coordinates
    }
    itemone.location = {
      type: 'Point',
      coordinates: item.geometry.coordinates[0][0]
    }
  
  
    itemlist.push(_.cloneDeep(itemone))
  })
  
  
  
  
  // 插入数据
  // await sequelize.sync({ force: true }); 
  // const newRecord = await ImgList.create(item);
  
  const newRecord = await ImgList.bulkCreate(itemlist);

}

main()